package com.yhsoft.wxprogram.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yhsoft.common.response.PageResult;
import com.yhsoft.common.vo.Result;
import com.yhsoft.goods.controller.response.GoodsOutVo;
import com.yhsoft.goods.service.IGoodsInfoService;
import com.yhsoft.wxprogram.controller.request.GoodsIdsInVo;
import com.yhsoft.wxprogram.po.GoodsPo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: yyyyyyyh
 * @create: 2023-10-12
 * @Version 1.0
 **/
@Api(tags = {"G-wx-商品信息接口"})
@RestController
@Slf4j
@RequestMapping("/wxApi/goods/")
public class WxMallGoodsController {

    @Autowired
    private IGoodsInfoService goodsInfoService;

    @ApiOperation("获取商品列表/搜索商品（旧）")
    @GetMapping("/getGoodsInfoList1")
    public Result<PageResult<GoodsPo>> getGoodsInfoList1(@RequestParam(value = "goodName", required = false) @ApiParam(value = "搜索关键词") String goodName,
                                                        @RequestParam(value = "goodsType", required = false)
                                                        @ApiParam(value = "商品类型：1-电影，2-蛋糕，3-电子券，4-api电商，5-线下供应商,多个用逗号拼接")
                                                                String goodsTypes,
                                                        @RequestParam(value = "pageNo") Long pageNo,
                                                        @RequestParam(value = "pageSize") Long pageSize) {
        IPage<GoodsPo> iPage = goodsInfoService.getGoodsListByCard(goodName, goodsTypes, pageNo, pageSize);
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("获取商品列表/搜索商品（新）")
    @GetMapping("/getGoodsInfoList")
    public Result<PageResult<GoodsPo>> getGoodsInfoList(@RequestParam(value = "goodName", required = false) @ApiParam(value = "搜索关键词") String goodName,
                                                        @RequestParam(value = "goodsType", required = false)
                                                        @ApiParam(value = "商品类型：1-电影，2-蛋糕，3-电子券，4-api电商，5-线下供应商,多个用逗号拼接")
                                                                String goodsTypes,
                                                        @RequestParam(value = "pageNo") Long pageNo,
                                                        @RequestParam(value = "pageSize") Long pageSize) {
        IPage<GoodsPo> iPage = goodsInfoService.getGoodsListByCard_new(goodName, goodsTypes, pageNo, pageSize);
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("查询商品详情(旧)")
    @GetMapping("/getGoodInfo1")
    public Result<GoodsOutVo> getGoodInfo(@RequestParam(value = "goodsId") Integer goodsId, @RequestParam(value = "skuId") Integer skuId) {
        GoodsOutVo outVo = goodsInfoService.getGoodInfoWx(goodsId);
        return Result.success(outVo);
    }

    @ApiOperation("查询商品详情(新)")
    @GetMapping("/getGoodInfo")
    public Result<GoodsOutVo> getGoodInfo_new(@RequestParam(value = "goodsId") Integer goodsId, @RequestParam(value = "skuId") Integer skuId) {
        GoodsOutVo outVo = goodsInfoService.getGoodInfoWx_new(goodsId);
        return Result.success(outVo);
    }

    @ApiOperation("查询商品运费（对接第三方）")
    @GetMapping("/getFreight")
    public Result<?> getFreight(@RequestParam(value = "goodsId") Integer goodsId) {

        return Result.success();
    }

    @ApiOperation("根据商品ids获取商品列表（旧）")
    @PostMapping("/getGoodsInfoListById1")
    public Result<PageResult<GoodsPo>> getGoodsInfoList(@RequestBody GoodsIdsInVo inVo) {
        IPage<GoodsPo> iPage = goodsInfoService.getGoodsInfoListById(inVo, inVo.getPageNo(), inVo.getPageSize());
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("根据商品ids获取商品列表(新)")
    @PostMapping("/getGoodsInfoListById")
    public Result<PageResult<GoodsPo>> getGoodsInfoList_new(@RequestBody GoodsIdsInVo inVo) {
        log.info("getGoodsInfoList_new:{}", inVo);
        IPage<GoodsPo> iPage = goodsInfoService.getGoodsInfoList_new(inVo, inVo.getPageNo(), inVo.getPageSize());
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("根据获取福利卡专题商品列表")
    @PostMapping("/getTopicGoodsList")
    public Result<PageResult<GoodsPo>> getTopicGoodsList(@RequestBody GoodsIdsInVo inVo) {
        log.info("getTopicGoodsList:{}", inVo);
        IPage<GoodsPo> iPage = goodsInfoService.getTopicGoodsList(inVo, inVo.getPageNo(), inVo.getPageSize());
        return Result.success(PageResult.valueOf(iPage));
    }
}
